package com.ynny.Dao.Impl;

import com.ynny.Dao.CourseManagerDao;
import com.ynny.Entity.Courses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class CourseImpl implements CourseManagerDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public int updateCourse(String coursesName) {
        String sql = "update courses set math = math - 1 where id = ?";
        return jdbcTemplate.update(sql,coursesName);
    }

    @Override
    public List<Courses> queryCourse() {
        String sql = "select * from courses";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Courses.class));
    }

    @Override
    public Courses queryCourseByName(String coursesName) {
        String sql = "select * from courses where coursesName = ?";
        return jdbcTemplate.queryForObject(sql,new BeanPropertyRowMapper<>(Courses.class),coursesName);
    }
}
